﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            //int[] mas = new int[] { 56, 32, 1, 100, -63, 99, 7, 10, 2, -10, 36, -2 , 0, 59};
            //char[] mas = new char[] { 'w', 't', 'f', 'a', 's', 'd', 'g', 'h', 'j', 'l' };
            string[] mas = new string[] { "qwety", "qwe", "qw", "asdfghj", "as", "asdfg" };
            for (int i = 0; i < mas.Length; i++)
            {
                Console.Write(mas[i] + "  ");
            }
            Console.WriteLine();
            for (int i = 1; i < mas.Length; i++)
            {
                //for (int j = 0; j < mas.Length - 1; j++)
                //{
                //    if (mas[i] < mas[j])
                //    {
                //        int tmp = mas[i];
                //        mas[i] = mas[j];
                //        mas[j] = tmp;
                //    }

                //}
                for (int j = mas.Length - i - 1; j < mas.Length - 1; j++)                
                {
                    //if (mas[j] > mas[j + 1])
                    //{
                    //    char tmp = mas[j];
                    //    mas[j] = mas[j + 1];
                    //    mas[j + 1] = tmp;
                    //}
                    //else
                    //{
                    //    break;
                    //}
                    string s1 = mas[j];
                    string s2 = mas[j + 1];
                    if (s1.Length >= s2.Length)
                    {
                        string sb = "";
                        for (int k = 0; k < s2.Length; k++)
                        {
                            sb += s2[k];
                            if (s1[k] > s2[k])
                            {
                                string tmp = mas[j];
                                mas[j] = mas[j + 1];
                                mas[j + 1] = tmp;
                                break;
                            }
                            else if (sb == s2 && s1.Length != s2.Length)
                            {
                                string tmp = mas[j];
                                mas[j] = mas[j + 1];
                                mas[j + 1] = tmp;
                            }
                        }
                    }
                    else if (s2.Length > s1.Length)
                    {
                        for (int k = 0; k < s1.Length; k++)
                        {
                            if (s1[k] > s2[k])
                            {
                                string tmp = mas[j];
                                mas[j] = mas[j + 1];
                                mas[j + 1] = tmp;
                                break;
                            }
                        }
                    }
                    //else
                    //{
                    //    string tmp = mas[j];
                    //    mas[j] = mas[j + 1];
                    //    mas[j + 1] = tmp;
                    //}

                }
            }
            for (int i = 0; i < mas.Length; i++)
            {
                Console.Write(mas[i] + "  ");
            }
            Console.WriteLine();
        }
    }
}
